﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Interactive.Utility.Extension;

namespace TravelLink.WebModel {
    public class WebHelper {

        #region Search Helper

        public static void GetSearchDate(int dt, out DateTime begin, out DateTime end) {
            DateTime now = DateTime.Now;
            begin = now;
            end = now;
            if (dt == 1) {
                begin = begin.AddDays(-7);
            }
            else if (dt == 2) {
                begin = begin.AddDays(-7 * 2);
            }

            else if (dt == 3) {
                begin = begin.AddMonths(-1);
            }
            else if (dt == 4) {
                begin = begin.AddMonths(-2);
            }
            else if (dt == 5) {
                begin = begin.AddMonths(-3);
            }
            else if (dt == 6) {
                begin = begin.AddMonths(-6);
            }
            else {
                begin = begin.AddMonths(-12);
            }
        }

        #endregion


        #region Query String Get
        public static string GetQueryStringStr(string key, string defVal = "") {
            return HttpContext.Current.Request.QueryString[key].AsStr(defVal);
        }

        public static int GetQueryStringInt(string key, int defVal = 0) {
            return GetQueryStringStr(key).AsInt(defVal);
        }


        public static DateTime GetQueryStringDatetime(string key) {
            return GetQueryStringStr(key).AsDatetime(DateTime.MaxValue);
        }

        public static double GetQueryStringDouble(string key, double defVal = 0.0) {
            return GetQueryStringStr(key).AsDouble(defVal);
        }

        public static short GetQueryStringShort(string key, short defVal = 0) {
            return GetQueryStringStr(key).AsShort(defVal);
        }

        public static bool GetQueryStringBool(string key, bool defVal = false) {
            return GetQueryStringStr(key).AsBool(defVal);
        }
        #endregion

        #region Form Get

        public static string GetFormStr(string key, string defVal = "") {
            return HttpContext.Current.Request.Form[key].AsStr(defVal);
        }

        public static int GetFormInt(string key, int defVal = 0) {
            return GetFormStr(key).AsInt(defVal);
        }

        public static double GetFormDouble(string key, double defVal = 0.0) {
            return GetFormStr(key).AsDouble(defVal);
        }

        public static short GetFormShort(string key, short defVal = 0) {
            return GetFormStr(key).AsShort(defVal);
        }

        public static bool GetFormBool(string key, bool defVal = false) {
            return GetFormStr(key).AsBool(defVal);
        }
        #endregion
    }
}
